"""代表一副牌"""
from python项目案例开发从入门到精通.扑克牌发牌游戏.Card import Card
from python项目案例开发从入门到精通.扑克牌发牌游戏.Hand import Hand


class Poke(Hand):
    def populate(self):  # 生成一副牌
        for suit in Card.SUITS:
            for rank in Card.RANKS:
                self.add(Card(rank, suit))

    def shuffle(self):  # 洗牌
        import random
        random.shuffle(self.cards)  # 随机打乱列表中的元素

    def deal(self, hands, per_hand=13):  # 发牌
        for rounds in range(per_hand):
            for hand in hands:
                if self.cards:
                    top_card = self.cards[0]
                    self.cards.remove(top_card)
                    hand.add(top_card)
                else:
                    print("牌已经发完了！")


# 主程序
if __name__ == '__main__':
    print("欢迎来到扑克牌发牌游戏！")
    # 4个玩家
    players = [Hand(), Hand(), Hand(), Hand()]
    # 生成一副牌
    poke1 = Poke()
    poke1.populate()  # 生成一副牌
    poke1.shuffle()  # 洗牌
    poke1.deal(players, 13)  # 发牌，每人13张牌
    # 输出每人手牌
    n = 1
    for hand in players:
        print("玩家{}的手牌：".format(n))
        print(hand)
        n += 1
    input("按任意键退出游戏...")
